<template>
	<el-card shadow="never">
		<el-form ref="form" :model="form" :rules="rules" label-width="120px" style="margin-top:20px;" label-position="top">
            <el-form-item label="纳税人设置">
                <sc-form-table ref="table" v-model="form.detail" :addTemplate="addTemplate" placeholder="暂无数据" height="600" hideAdd hideDelete showIndex>
                    <el-table-column label="参数名称" align="center" prop="switch_name" width="150"></el-table-column>
                    <el-table-column label="状态" align="center" prop="technology">
                        <template #default="scope">
                            <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="switchChange(e,scope.$index)"></el-switch>
                        </template>
                    </el-table-column>
                </sc-form-table>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submit">保存</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	export default {
		props:{
			info:Object
		},
		data() {
			return {
				form: {
					detail: [],
				},
				rules: {
				},
			}
		},
        mounted () {
            this.getParams();
        },
		methods: {
			/**获取纳税人*/
            async getParams(){
                var res = await this.$API.setting.setparams.get({type: 3});
                this.form.detail = res.data
            },
			/**保存纳税人*/
            async submit(){
                var res = await this.$API.setting.editparams.post(this.form);
                if(res.code == 1){
                    this.getParams();
	                this.$message.success("操作成功")
                }else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
            },
            switchChange(e,index){
                this.form.detail.forEach((item, i) => {
                    item.status = (i == index) ? 0 : 1;
                });
            },
		},
	}
</script>

<style>
</style>
